package org.class2table.sync;

import org.class2table.sync.bean.CompareResult;
import org.class2table.sync.bean.ExeSqlInfo;
import org.class2table.sync.bean.TableResult;
import org.class2table.core.dictionary.Constants;

import java.util.List;

public class CompareResultsUtil {

    public static void printCompareResults(List<CompareResult> compareResults) {
        System.out.println("\n👇👇👇👇👇compare result print👇👇👇👇👇");
        int index = 1;
        for (CompareResult compareResult : compareResults) {
            String dbName = compareResult.getDbName();
            System.out.println("\n==@@ " + index++ + "==");
            System.out.println("# db : {" + dbName + "}");
            List<TableResult> tableResults = compareResult.getTableResults();
            for (TableResult tableResult : tableResults) {
                String tableName = tableResult.getTableName();
                System.out.println("# table : {" + tableName + "}");
                List<ExeSqlInfo> exeSqlInfos = tableResult.getExeSqlInfos();

                System.out.println("# create table sql { ");
                exeSqlInfos
                        .stream().filter(
                        t -> Constants.OperationType.CREATE_TABLE.equals(t.getOperationType())
                ).forEach(q -> q.getSqls().forEach(System.out::println));
                System.out.println("}");

                System.out.println("# drop primary key sql { ");
                exeSqlInfos
                        .stream().filter(
                        t -> Constants.OperationType.DROP_PRIMARY_KEY.equals(t.getOperationType())
                ).forEach(q -> q.getSqls().forEach(l -> {System.out.println("            " + l);}));
                System.out.println("}");

                System.out.println("# add column sql list { ");
                exeSqlInfos
                        .stream().filter(
                        t -> Constants.OperationType.ADD_COLUMN.equals(t.getOperationType())
                ).forEach(q -> q.getSqls().forEach(l -> {System.out.println("            " + l);}));
                System.out.println("}");

                System.out.println("# modify column sql list { ");
                exeSqlInfos
                        .stream().filter(
                        t -> Constants.OperationType.MODIFY_COLUMN.equals(t.getOperationType())
                ).forEach(q -> q.getSqls().forEach(l -> {System.out.println("            " + l);}));
                System.out.println("}");

                System.out.println("# drop column sql list { ");
                exeSqlInfos
                        .stream().filter(
                        t -> Constants.OperationType.DROP_COLUMN.equals(t.getOperationType())
                ).forEach(q -> q.getSqls().forEach(l -> {System.out.println("            " + l);}));
                System.out.println("}");

                System.out.println("# add primary key sql { ");
                exeSqlInfos
                        .stream().filter(
                        t -> Constants.OperationType.ADD_PRIMARY_KEY.equals(t.getOperationType())
                ).forEach(q -> q.getSqls().forEach(l -> {System.out.println("            " + l);}));
                System.out.println("}");
            }
        }
        System.out.println("\n👆👆👆👆👆compare result print👆👆👆👆👆");
    }
}
